//
//  SPViewController.m
//  SuperPatrner
//
//  Created by EvanZ on 15/3/28.
//  Copyright (c) 2015年 EvanZ. All rights reserved.
//

#import "SPViewController.h"

@interface SPViewController ()

@end

@implementation SPViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - alertview

- (void)alertWithTitle:(NSString *)title message:(NSString *)message
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alertView show];
}

#pragma mark -
#pragma mark MBProgressHUD Methods

-(void) showProgress{
    if (nil != self.navigationController.view) {
        self.progressHUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        self.progressHUD.delegate = self;
        isAutoCloseProgress = NO;
    }
}

-(void) showProgressWithText : (NSString *) context withDelayTime : (NSUInteger) sec{
    if (nil == self.progressHUD) {
        [self showProgress];
    }
    
    if (sec <= 1) {
        sec = 2;
    }
    self.progressHUD.mode = MBProgressHUDModeText;
    self.progressHUD.detailsLabelText = context;
    [self.progressHUD hide:YES afterDelay:sec];
}

-(void) showProgressWithText:(NSString *)text{
    [self showProgress];
    self.progressHUD.detailsLabelText = text;
}

-(void) showProgressWithText:(NSString *)text dimBackground:(BOOL)isBackground{
    [self showProgressWithText:text];
    self.progressHUD.dimBackground = isBackground;
}

-(void) showProgressAutoCloseInNetwork{
    [self showProgress];
    isAutoCloseProgress = YES;
}

-(void) showProgressAutoCloseInNetwork:(NSString *)text{
    [self showProgressAutoCloseInNetwork];
    self.progressHUD.detailsLabelText = text;
}

-(void) showProgressAutoCloseInNetwork : (NSString *) text dimBackground : (BOOL) isBackground{
    [self showProgressAutoCloseInNetwork:text];
    self.progressHUD.dimBackground = isBackground;
}

-(void) autoCloseProgress{
    if (isAutoCloseProgress && nil != self.progressHUD) {
        [self.progressHUD hide:YES];
    }
}

-(void) showProgressAutoWithText : (NSString *) context withDelayTime : (NSUInteger) sec{
    [self showProgressWithText:context withDelayTime:sec];
}

-(void) closeProgress{
    if (nil != self.progressHUD) {
        [self.progressHUD hide:YES];
    }
}

-(void) showWhileExecuting : (SEL) sel withText : (NSString *) text withDetailText : (NSString *) detailText{
    if (nil != self.progressHUD) {
        return;
    }
    self.progressHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:self.progressHUD];
    self.progressHUD.delegate = self;
    
    if (text.length != 0) {
        self.progressHUD.labelText = text;
    }
    
    if (detailText.length != 0) {
        self.progressHUD.detailsLabelText = detailText;
    }
    
    [self.progressHUD showWhileExecuting:sel onTarget:self withObject:nil animated:YES];
}

-(void) showProgressWithText:(NSString *)text closeAfterDelayTime: (NSUInteger) sec
{
    [self showProgress];
    self.progressHUD.labelText = text;
    self.progressHUD.mode = MBProgressHUDModeCustomView;
    [self.progressHUD hide:YES afterDelay:sec];
}

- (void)showHintProgressWithText:(NSString *)text{
    [self showProgressWithText:text closeAfterDelayTime:1.2];
}

#pragma mark -
#pragma mark MBProgressHUDDelegate methods

- (void)hudWasHidden:(MBProgressHUD *)hud {
    [self.progressHUD removeFromSuperview];
    self.progressHUD = nil;
}


@end

